package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Car;
import cn.wolfcode.crm.mapper.CarMapper;
import cn.wolfcode.crm.query.ObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.ICarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CarServiceImpl implements ICarService {
    @Autowired
    private CarMapper carMapper;

    public void save(Car record) {

        carMapper.insert(record);
    }

    public void delete(Long id) {
            carMapper.deleteByPrimaryKey(id);


    }

    public void update(Car record) {
        carMapper.updateByPrimaryKey(record);
    }

    public Car get(Long id) {
        Car employee = carMapper.selectByPrimaryKey(id);
        return employee;
    }

    public List<Car> getAll() {

        return carMapper.selectAll();
    }

    public PageResult<Car> query(ObjectQuery qo) {
        int totalCount = carMapper.queryForCount(qo);
        if (totalCount == 0) {
            return new PageResult<Car>(totalCount, Collections.<Car>emptyList());
        }


        return new PageResult<Car>(totalCount, carMapper.queryForList(qo));
    }




}
